package com.zrc.superframe_base.mvx.mvp

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.zrc.superframe_base.mvx.base.BaseFragment

/**
 * @Author: superman
 * @CreateTime: 2020/7/4
 * @Describe: MVP模式fragment基类
 */
abstract class BaseMvpFragment<V, P : BasePresenter<V>?> : BaseFragment() {

    var mPresenter: P? = null

    private var mView: View? = null

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mView=inflater.inflate(getLayoutID(), container, false)
        return mView
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        mPresenter = createPresenter()
        initView(mView)
        initListener()
        initData()
    }

    protected abstract fun createPresenter(): P

    protected abstract fun getLayoutID(): Int

    open fun initView(contentView: View?) {}

    open fun initData() {}

    open fun initListener() {}

    override fun onDestroy() {
        super.onDestroy()
        mPresenter?.detachView()
    }
}